package cn.hd.authorService.handler;

import cn.hd.commonService.utils.ResponseUtils;
import cn.hd.commonService.vo.Result;
import com.alibaba.fastjson.JSON;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @CreatedBy dsl
 * 用户无权限处理器
 */
@Component
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        Result result = new Result(HttpStatus.FORBIDDEN.value(),"您的权限不足",null);
        String json = JSON.toJSONString(result);
        //处理异常
        ResponseUtils.renderString(HttpStatus.FORBIDDEN.value(),response,json);
    }
}
